package org.javaboy.shiro;

import org.apache.shiro.authc.credential.DefaultPasswordService;
import org.apache.shiro.crypto.hash.DefaultHashService;
import org.apache.shiro.crypto.hash.SimpleHash;

public class PasswordEncoder {
    public static void main(String[] args) {
        SimpleHash md5 = new SimpleHash("MD5", "123");
        System.out.println("md5 = " + md5);
        //密码加密服务
        DefaultPasswordService passwordService = new DefaultPasswordService();
        String s = passwordService.encryptPassword("123");
        System.out.println("s = " + s);
        DefaultHashService hs = new DefaultHashService();
        //使用 BCrypt 加密方案
        hs.setDefaultAlgorithmName("2y");
        passwordService.setHashService(hs);
        String s1 = passwordService.encryptPassword("123");
        System.out.println("s1 = " + s1);
        boolean b1 = passwordService.passwordsMatch("123", "$shiro2$argon2id$v=19$t=1,m=65536,p=4$W9VoA78cdSFtW0QqjjWOwQ$MHuxy1cZOnYss1ynz+JT6crJf+5a2xAKiV93/EsY++U");
        boolean b2 = passwordService.passwordsMatch("123", "$shiro2$2y$10$/8/OS7u2wKIzGQ32sXDJkuD6R0VGueieLRakSaPtlQNeOUYMv1hmG");
        System.out.println("b1 = " + b1);
        System.out.println("b2 = " + b2);
    }
}